#include <iostream>
#include <vector>
#include <sys/types.h>
#include <unistd.h>

using namespace std;

const int num = 10;

void SubprocessRun()
{
    while(true)
    {
        cout << "I am Sub process, pid : " << getpid() << "ppid: " << getppid() << std::endl << std::flush;
        sleep(10);
    }
}

int main()
{
    vector<pid_t> allchild;
    for(int i = 0; i < num; i++)
    {
        pid_t id = fork();
        if(id == 0)
        {
            //子进程
            SubprocessRun();
        }
        //父进程
        allchild.push_back(id);
    }
        sleep(100);
        //父进程
        cout << "我所有的孩子是 : ";
        for(auto child : allchild)
        {
            cout << child << " ";
        }
        cout << endl;

        sleep(10);
        while(true)
        {
            cout << "我是父进程, pid : " << getpid() << endl;
            sleep(1);
        }
        return 0;
}
